<template>
  <div class="container" ref="mainCon">
    <topTitle :titleText="titleText" :titleExplain="titleExplain"></topTitle>
    <div class="desc">更新时间，报表每日23点更新</div>
    <div class="mainCon">
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <el-col :lg="8" :xl="6">
            <el-form-item label="区域" class="row-padding-bottom">
              <el-cascader
                ref="manageArea"
                v-model="areaId"
                :options="areasOptions"
                @change="getAreaId"
                :props="{ checkStrictly: true }"
                clearable
                filterable
              ></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="行业" class="row-padding-bottom">
              <el-select
                v-model="filterField.industryId"
                filterable
                placeholder="请选择行业"
                clearable
              >
                <el-option
                  v-for="item in industryOptions"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="项目名称" class="row-padding-bottom">
                <el-input
                  v-model="filterField.projectName"
                  placeholder="请输入项目名称"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="建档状态" class="row-padding-bottom">
                <el-select
                  v-model="filterField.status"
                  filterable
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="item in statusOptions"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item label="">
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchList"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
            <el-button
              class="commonBut saveBtn funComBut"
              icon="icon iconfont icondaochu"
              @click="getExportList"
            >
              <span class="opetareText">导出</span>
            </el-button>
          </el-col>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div class="proDetailsListBox">
        <el-table
          :data="tableList"
          @sort-change="sortChange"
          v-loading="loading"
          :max-height="tableHeight"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column
            prop="name"
            label="中标项目名称"
            min-width="230"
            :formatter="formatTd"
          >
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.name"
                :columnName="'name'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            v-if="isEsUser()"
            label="是否被标注为黑名单"
            min-width="160"
            align="center"
            :formatter="formatTd"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.isBlack === 1">是</span>
              <span v-else-if="scope.row.isBlack === 0">否</span>
              <span v-else>未知</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="areaName"
            label="所在行政区域"
            min-width="120"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="industryName"
            label="行业分类"
            min-width="100"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="tenderName"
            label="招标人名称"
            min-width="230"
            :formatter="formatTd"
          >
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.tenderName"
                :columnName="'tenderName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="bidCompanyName"
            label="中标人公司名称"
            min-width="230"
            :formatter="formatTd"
          >
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.bidCompanyName"
                :columnName="'bidCompanyName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="linkTel"
            label="联系方式"
            min-width="120"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="bidPrice"
            label="投标报价（元）"
            sortable="custom"
            min-width="160"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="timeLimitDescription"
            label="工期（天）"
            min-width="140"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="statusStr"
            label="建档状态"
            min-width="100"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="createTime"
            label="录入时间"
            sortable="custom"
            min-width="160"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            label="操作"
            align="left"
            fixed="right"
            min-width="120"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                v-if="scope.row.status === '0'"
                @click="toEdit(scope.row)"
                >建档</el-link
              >
              <el-link type="primary" v-else @click="toDetail(scope.row)"
                >查看项目</el-link
              >
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关数据"></emptyTable>
          </div>
        </el-table>
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
          @getpageNo="getpageNo"
          @getpageSize="getpageSize"
        ></Pagination>
      </div>
    </div>
  </div>
</template>

<script>
import common from '../../kits/common'
import { mapState } from 'vuex'
export default {
  name: 'biddingProjectList',
  data() {
    return {
      titleText: '招标局项目',
      titleExplain: '所有招标局定期推送的项目',
      tableHeight: null,
      advanced: false,
      areaId: [],
      filterField: {
        projectName: '',
        areaCode: '',
        industryId: '',
        status: '',
      },
      statusOptions: [
        {
          name: '未建档',
          code: '0',
        },
        {
          name: '已建档',
          code: '1',
        },
      ],
      requestUrl: '/api-p/project/tender/base/list',
      pageSize: 20,
      pageNo: 1,
      tableList: [],
    }
  },
  computed: { ...mapState(['areasOptions', 'industryOptions']) },
  mounted() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData(this.pageNo, this.pageSize)
    })
    this.$nextTick(function () {
      this.tableHeight = window.innerHeight - 324
      // 监听窗口大小变化
      let self = this
      window.onresize = function () {
        self.tableHeight = window.innerHeight - 324
      }
    })
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getpageSize(val) {
      this.pageSize = val
    },
    getpageNo(val) {
      this.pageNo = val
    },
    // 是否有导出数据
    getExports() {
      return this.axios({
        method: 'post',
        url: this.requestUrl,
        data: Object.assign(this.filterField, {
          pageSize: 20,
          pageNo: 1,
        }),
      })
        .then((response) => {
          if (!response.data.hasError) {
            return response.data.result.results &&
              response.data.result.results.length > 0
              ? true
              : false
          } else {
            this.$message.error(response.data.errorMsg)
          }
        })
        .catch((error) => {
          if (error.response) {
            this.$message.error(error.response.data)
          }
        })
    },
    async getExportList() {
      const flag = await this.getExports()
      let { projectName, areaCode, industryId, status, sortField, sort } =
        this.filterField
      if (flag) {
        window.location.href =
          common.commonApi +
          'api-p/project/tender/base/export?projectName=' +
          projectName +
          '&areaCode=' +
          areaCode +
          '&industryId=' +
          industryId +
          '&status=' +
          status +
          '&sortField=' +
          sortField +
          '&sort=' +
          sort +
          '&access_token=' +
          localStorage.getItem('access_token')
      } else {
        this.$message.warning('暂无数据导出')
      }
    },
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },
    searchList() {
      this.$refs.pagination.getTableListData()
    },
    toEdit(row) {
      this.$router.push({
        path: '/home/projectDeduplication/projectInterfaceDetail',
        name: 'projectInterfaceDetail',
        query: {
          id: row.id,
          type: 'bidding',
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/dataDocking/biddingProjectList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    toDetail(row) {
      this.$router.push({
        path: '/home/monitorProjectManagement/projectDetail',
        name: 'projectDetail',
        query: {
          projectId: row.projectCode,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/project/projectList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    //获取选中的区域最后一级id
    getAreaId() {
      var areaId = this.areaId[this.areaId.length - 1]
        ? this.areaId[this.areaId.length - 1]
        : ''
      this.filterField.areaCode = areaId
    },
  },
}
</script>

<style lang="less" scoped>
.proDetailsListBox {
  padding: 24px;
  background: #fff;
}
.desc {
  position: absolute;
  top: 30px;
  right: 20px;
  font-size: 14px;
  color: #009588;
}

.theme_default .desc {
  color: #3189ea;
}
@import '../../../static/css/filterArea.less';
</style>
